<!-- src/views/Home.vue -->
<template>
  <div class="home">
    <div>
      <p1>check out say hi </p1>
      <p>{{ message }}</p>
    </div>
    <!-- 轮播横幅 -->
    <section class="hero-section">
      <div class="hero-content">
        <h1 class="hero-title">欢迎来到 WineShop</h1>
        <p class="hero-subtitle">大米原浆酒，精选优质大米，小曲发酵，口感清柔绵甜，纯净健康，适饮百搭。</p>
        <p class="hero-subtitle">工艺传统，酒体纯净，口感绵甜清爽，酒精度适中，适合日常小酌、佐餐解腻，饮后舒适不上头。</p>
        <div class="hero-actions">
          <button class="btn btn-primary btn-large" @click="goToSearch">开始选购</button>
          <button class="btn btn-secondary btn-large" @click="scrollToProducts">查看推荐</button>
        </div>
      </div>

      <div class="hero-image">
        <div class="wine-bottles">🍶🥂🍺</div>
      </div>
    </section>

    <!-- 统计信息 -->
    <section class="stats-section">
      <div class="stats-grid">
        <div class="stat-item">
          <div class="stat-number">{{ products.length }}</div>
          <div class="stat-label">精选白酒</div>
        </div>
        <div class="stat-item">
          <div class="stat-number">{{ users.length }}</div>
          <div class="stat-label">用户数量</div>
        </div>
        <div class="stat-item">
          <div class="stat-number">100+</div>
          <div class="stat-label">顾客数量</div>
        </div>
        <div class="stat-item">
          <div class="stat-number">24/7</div>
          <div class="stat-label">在线服务</div>
        </div>
      </div>
    </section>

    <!-- 推荐产品 -->
    <section class="featured-section" ref="productsSection">
      <div class="section-header">
        <h2>🌟 精选推荐</h2>
        <p>为您精心挑选的优质白酒</p>
      </div>

      <div class="products-grid container">
        <ProductCard v-for="product in featuredGoods" :key="product.id" :product="product" @view-details="viewProductDetails" @add-to-cart="addToCart" />
      </div>

      <div class="section-footer">
        <button class="btn btn-primary" @click="goToSearch">查看更多商品 →</button>
      </div>
    </section>

    <!-- 特色服务 -->
    <section class="features-section">
      <div class="section-header">
        <h2>🎯 我们的服务</h2>
        <p>专业的白酒酿造，为您提供最健康的饮酒选择</p>
      </div>

      <div class="features-grid">
        <div class="feature-item">
          <div class="feature-icon">🚚</div>
          <h3>快速配送</h3>
          <p>市区范围内24小时内发货，确保白酒新鲜到达</p>
        </div>
        <div class="feature-item">
          <div class="feature-icon">🏆</div>
          <h3>品质保证</h3>
          <p>所有的酿造原材料均经过精心挑选，品质有保障</p>
        </div>
        <div class="feature-item">
          <div class="feature-icon">💎</div>
          <h3>专业服务</h3>
          <p>专业的酿酒师傅为您提供个性化的选酒建议</p>
        </div>
        <div class="feature-item">
          <div class="feature-icon">🎁</div>
          <h3>会员福利</h3>
          <p>丰富的会员专享活动和积分兑换优惠</p>
        </div>
      </div>
    </section>
  </div>
</template>

<script setup>
import { computed, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useWineStore } from '@/store'
import ProductCard from '@/components/ProductCard.vue'
import { useGoods } from '@/composables/useGoods'
import { sayHi } from '@/api/product'

const { loadFeaturedGoods, loadGoodsList } = useGoods()

const router = useRouter()
const store = useWineStore()
const productsSection = ref(null)
const message = ref('')

const featuredGoods = computed(() => store.featuredGoods)
const products = computed(() => store.products)
const users = computed(() => store.users)

const goToSearch = () => {
  router.push('/search')
}

const scrollToProducts = () => {
  productsSection.value?.scrollIntoView({ behavior: 'smooth' })
}

const viewProductDetails = product => {
  alert(`查看商品详情: ${product.name}\n价格: ¥${product.price}\n产地: ${product.origin}\n年份: ${product.year}年\n描述: ${product.description}`)
}

const addToCart = product => {
  // 这里可以添加购物车逻辑
  console.log('添加到购物车:', product)
}
async function init() {
  const result = await sayHi()
  message.value = result
}

onMounted(() => {
  loadFeaturedGoods()
  loadGoodsList()
  init()
  console.log('主页products 内容：', products.value)
})
</script>

<style scoped>
.home {
  min-height: 100vh;
}

/* 英雄区域 */
.hero-section {
  background: linear-gradient(135deg, #8b4513 0%, #a0522d 50%, #cd853f 100%);
  color: white;
  padding: 80px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 500px;
  position: relative;
  overflow: hidden;
}

.hero-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* background: url('book.svg'); 改为你的本地图片路径 */
  background-size: cover; /* 可选：根据需要调整尺寸 */
  background-repeat: no-repeat; /* 可选：不重复 */
  animation: float 20s infinite linear;
}

@keyframes float {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-20px);
  }
}

.hero-content {
  flex: 1;
  max-width: 600px;
  z-index: 2;
  position: relative;
}

.hero-title {
  font-size: 3.5rem;
  font-weight: bold;
  margin-bottom: 20px;
  line-height: 1.2;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.hero-subtitle {
  font-size: 1.3rem;
  margin-bottom: 40px;
  opacity: 0.9;
  line-height: 1.6;
}

.hero-actions {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.btn-large {
  padding: 15px 30px;
  font-size: 1.1rem;
  font-weight: bold;
  border-radius: 8px;
  transition: all 0.3s;
}

.btn-large:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.hero-image {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2;
  position: relative;
}

.wine-bottles {
  font-size: 8rem;
  animation: bounce 2s infinite;
}

@keyframes bounce {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

/* 统计区域 */
.stats-section {
  background: white;
  padding: 60px 20px;
  box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.1);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 40px;
  max-width: 1000px;
  margin: 0 auto;
}

.stat-item {
  text-align: center;
  padding: 20px;
  border-radius: 10px;
  transition: transform 0.3s;
}

.stat-item:hover {
  transform: translateY(-5px);
}

.stat-number {
  font-size: 3rem;
  font-weight: bold;
  color: #8b4513;
  margin-bottom: 10px;
}

.stat-label {
  font-size: 1.1rem;
  color: #666;
  font-weight: 500;
}

/* 推荐产品区域 */
.featured-section {
  padding: 80px 20px;
  background: #f8f9fa;
}

.section-header {
  text-align: center;
  margin-bottom: 60px;
}

.section-header h2 {
  font-size: 2.5rem;
  color: #2c3e50;
  margin-bottom: 15px;
}

.section-header p {
  font-size: 1.2rem;
  color: #666;
  max-width: 600px;
  margin: 0 auto;
}

.products-grid {
  display: grid;
  flex-wrap: wrap;
  justify-content: flex-start;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.section-footer {
  text-align: center;
  margin-top: 40px;
}

/* 特色服务区域 */
.features-section {
  padding: 80px 20px;
  background: white;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 40px;
  max-width: 1000px;
  margin: 0 auto;
}

.feature-item {
  text-align: center;
  padding: 30px 20px;
  border-radius: 15px;
  background: #f8f9fa;
  transition: all 0.3s;
  border: 2px solid transparent;
}

.feature-item:hover {
  transform: translateY(-5px);
  border-color: #8b4513;
  background: white;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.feature-icon {
  font-size: 3rem;
  margin-bottom: 20px;
}

.feature-item h3 {
  font-size: 1.3rem;
  color: #2c3e50;
  margin-bottom: 15px;
}

.feature-item p {
  color: #666;
  line-height: 1.6;
}

@media (max-width: 768px) {
  .hero-section {
    flex-direction: column;
    text-align: center;
    padding: 60px 20px;
  }

  .hero-title {
    font-size: 2.5rem;
  }

  .hero-subtitle {
    font-size: 1.1rem;
  }

  .hero-actions {
    justify-content: center;
  }

  .wine-bottles {
    font-size: 4rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }

  .products-grid {
    grid-template-columns: 1fr;
  }

  .features-grid {
    grid-template-columns: 1fr;
  }
}
</style>
